from django.shortcuts import render

# Create your views here.
import logging
from rest_framework import filters, status
from rest_framework import viewsets
from .models import Monitor
from . import serializers
from rest_framework.decorators import action
from rest_framework.response import Response
from django_filters import rest_framework as django_filters


class MonitorFilter(django_filters.FilterSet):
    describe = django_filters.CharFilter(field_name="describe", lookup_expr="icontains")


    class Meta:
        model = Monitor
        fields = ["describe"]


logger = logging.getLogger('dev07')

class MonitorViewSet(viewsets.ModelViewSet):
    """
    """
    queryset = Monitor.objects.all()
    serializer_class = serializers.MonitorModelSerailizer

    # filter_backends = [filters.SearchFilter, filters.OrderingFilter]
    filter_backends = [django_filters.DjangoFilterBackend, filters.OrderingFilter]
    filterset_class = MonitorFilter
    # filterset_class = DailyFilter
    # search_fields = ['=name', '=leader', '=id']
    ordering_fields = ['finish_time']